package com.daohang361.imqq.Asycore;

import java.io.IOException;

import org.apache.mina.core.session.IoSession;

import com.daohang361.imqq.ServerContex.ServerContex;
import com.daohang361.imqq.ServerContex.SessionContex;

/**
 * 主监听客户端程序服务
 * This is not just an QQ,also is an open source frame
 * and you could modify this code.
 *上传图片地址124.115.6.48:8000
 * @author naner
 */
public class AsyProtocolQQ implements Runnable{
       private static final long serialVersionUID = 1L;
       private QQUser user=null;

       static{
    	   ServerContex.initLoader();//加载QQ登陆初始化步骤
    	   Thread heartbeat= new Thread(new HeartbeatThread());//心跳线程
    	   heartbeat.start();
    	   }
       
	public AsyProtocolQQ(QQUser user) throws IOException {
		this.user=user;
		Thread thread = new Thread(this);
		thread.start();
       	}

	@Override
	public void run() {
	
        /**
         * 初始化sessionQQ
         */
        user.init();
        SessionContex.saveQQUser(user.getQq(), user);//将用户信息保存到session之中
		   /**
		    * 初始化连接
		    */
           Connector defualtConnector = new Connector();
		   IoSession session = defualtConnector.redirect();
		   SessionContex.saveSessionConnector(user.getQq(),defualtConnector);
		   session.write(user);
	}
	
    /**
     * 入口程序
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws Exception {
//     
     QQUser qq2 =new QQUser();
 	 qq2.setQq(1714114540);
 	 qq2.setPasswd("likun7800");
     new AsyProtocolQQ(qq2);
//     
// 	QQUser qq3 =new QQUser();
//	 qq3.setQq(273493020);
//	 qq3.setPasswd("wzd19700105");
//     new AsyProtocolQQ(qq3);
// 	 
//	 	QQUser qq4 =new QQUser();
//		 qq4.setQq(178816340);
//		 qq4.setPasswd("a2353163");
//	     new AsyProtocolQQ(qq4);
//    	QQ2011.RandomKey();
//     QQUser qq =new QQUser();
//	   qq.setQq(526868457);
//	   qq.setPasswd("likun@87422");
//      new AsyProtocolQQ(qq);
//      QQUser qq =new QQUser();
//      qq.setQq(593952652  );
//      qq.setPasswd("qq123456");
//      new AsyProtocolQQ(qq);
        }

}


